﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;


namespace FAP.DataAccess.BLL
{
    public class comment
    {
        public int id { get; set; }
        public int idtaikhoan { get; set; }
        public int idbaiviet { get; set; }
        public string link { get; set; }
        public string nguoitao { get; set; }
        public string tieude { get; set; }
        public string noidung { get; set; }
        public DateTime ngaytao { get; set; }
        public bool isdeleted { get; set; }
        //public taikhoan taikhoan { get { return taikhoan.taikhoanSelectRow(idtaikhoan); } }
        //public baiviet baiviet { get { return baiviet.baivietSelectRow(idbaiviet); } }

        #region commentSelectAll
        public static List<comment> commentSelectAll()
        {
            IDataReader dr = FAP.DataAccess.DAL.commentSelectAll();
            List<comment> commentList = new List<comment>();
            while (dr.Read())
            {
                comment mycomment = new comment
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    idbaiviet = !dr.IsDBNull(dr.GetOrdinal("idbaiviet")) ? (int)dr["idbaiviet"] : 0,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    nguoitao = !dr.IsDBNull(dr.GetOrdinal("nguoitao")) ? (string)dr["nguoitao"] : null,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false
                };
                commentList.Add(mycomment);
            }
            dr.Close();
            dr.Dispose();
            return commentList;
        }
        #endregion

        #region commentSelectRow
        public static comment commentSelectRow(int id)
        {
            IDataReader dr = FAP.DataAccess.DAL.commentSelectRow(id);
            comment comment = null;

            if (dr.Read())
            {
                comment = new comment
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    idbaiviet = !dr.IsDBNull(dr.GetOrdinal("idbaiviet")) ? (int)dr["idbaiviet"] : 0,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    nguoitao = !dr.IsDBNull(dr.GetOrdinal("nguoitao")) ? (string)dr["nguoitao"] : null,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,

                };
            }
            dr.Close();
            dr.Dispose();
            return comment;
        }
        #endregion

        #region commentSelectRowByForeignKey_idtaikhoan
        public static List<comment> commentSelectRowByForeignKey_idtaikhoan(int idtaikhoan)
        {
            IDataReader dr = FAP.DataAccess.DAL.commentSelectRowByForeignKey_idtaikhoan(idtaikhoan);
            List<comment> commentList = new List<comment>();
            while (dr.Read())
            {
                comment mycomment = new comment
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    idbaiviet = !dr.IsDBNull(dr.GetOrdinal("idbaiviet")) ? (int)dr["idbaiviet"] : 0,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    nguoitao = !dr.IsDBNull(dr.GetOrdinal("nguoitao")) ? (string)dr["nguoitao"] : null,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false
                };
                commentList.Add(mycomment);
            }
            dr.Close();
            dr.Dispose();
            return commentList;
        }
        #endregion

        #region commentSelectRowByForeignKey_idbaiviet
        public static List<comment> commentSelectRowByForeignKey_idbaiviet(int idbaiviet)
        {
            IDataReader dr = FAP.DataAccess.DAL.commentSelectRowByForeignKey_idbaiviet(idbaiviet);
            List<comment> commentList = new List<comment>();
            while (dr.Read())
            {
                comment mycomment = new comment
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    idbaiviet = !dr.IsDBNull(dr.GetOrdinal("idbaiviet")) ? (int)dr["idbaiviet"] : 0,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    nguoitao = !dr.IsDBNull(dr.GetOrdinal("nguoitao")) ? (string)dr["nguoitao"] : null,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false
                };
                commentList.Add(mycomment);
            }
            dr.Close();
            dr.Dispose();
            return commentList;
        }
        #endregion

        #region commentSelectRowByForeignKey_idtaikhoan_idbaiviet
        public static List<comment> commentSelectRowByForeignKey_idtaikhoan_idbaiviet(int idtaikhoan, int idbaivi)
        {
            IDataReader dr = FAP.DataAccess.DAL.commentSelectRowByForeignKey_idtaikhoan_idbaiviet(idtaikhoan, idbaivi);
            List<comment> commentList = new List<comment>();
            while (dr.Read())
            {
                comment mycomment = new comment
                {
                    id = !dr.IsDBNull(dr.GetOrdinal("id")) ? (int)dr["id"] : 0,
                    idtaikhoan = !dr.IsDBNull(dr.GetOrdinal("idtaikhoan")) ? (int)dr["idtaikhoan"] : 0,
                    idbaiviet = !dr.IsDBNull(dr.GetOrdinal("idbaiviet")) ? (int)dr["idbaiviet"] : 0,
                    link = !dr.IsDBNull(dr.GetOrdinal("link")) ? (string)dr["link"] : null,
                    nguoitao = !dr.IsDBNull(dr.GetOrdinal("nguoitao")) ? (string)dr["nguoitao"] : null,
                    tieude = !dr.IsDBNull(dr.GetOrdinal("tieude")) ? (string)dr["tieude"] : null,
                    noidung = !dr.IsDBNull(dr.GetOrdinal("noidung")) ? (string)dr["noidung"] : null,
                    ngaytao = !dr.IsDBNull(dr.GetOrdinal("ngaytao")) ? (DateTime)dr["ngaytao"] : DateTime.Now,
                    isdeleted = !dr.IsDBNull(dr.GetOrdinal("isdeleted")) ? (bool)dr["isdeleted"] : false,
                };
                commentList.Add(mycomment);
            }
            dr.Close();
            dr.Dispose();
            return commentList;
        }
        #endregion

        #region commentInsertRow
        public static void commentInsertRow(int idtaikhoan, int idbaiviet, string link, string nguoitao, string tieude, string noidung, DateTime ngaytao, bool isdeleted)
        {
            FAP.DataAccess.DAL.commentInsertRow(idtaikhoan, idbaiviet, link, nguoitao, tieude, noidung, ngaytao, isdeleted);
        }
        #endregion

        #region commentUpdateRow
        public static void commentUpdateRow(int id, int idtaikhoan, int idbaiviet, string link, string nguoitao, string tieude, string noidung, DateTime ngaytao, bool isdeleted)
        {
            FAP.DataAccess.DAL.commentUpdateRow(id, idtaikhoan, idbaiviet, link, nguoitao, tieude, noidung, ngaytao, isdeleted);
        }
        #endregion

        #region commentDeleteRow
        public static void commentDeleteRow(int id)
        {
            FAP.DataAccess.DAL.commentDeleteRow(id);
        }
        #endregion
    }
}